//====================================================================================================
// Filename:	CharacterJabRight.cpp
// Created by:	Ali Talhouni
//====================================================================================================

//====================================================================================================
// Includes
//====================================================================================================

#include "CharacterJabRight.h"

#include "fighter.h"

//====================================================================================================
// Class Definitions
//====================================================================================================

CharacterJabRight::CharacterJabRight(fighter* pOwner)
	: CharacterState(pOwner, "JabRight")
	, mIsPlaying(false)
{
	// Empty
}

//----------------------------------------------------------------------------------------------------

CharacterJabRight::~CharacterJabRight()
{
	// Empty
}

//----------------------------------------------------------------------------------------------------

void CharacterJabRight::Load(FILE* pFile)
{
	//Read state amount
	int statecount=0;
	fscanf_s(pFile, "%*s %d", &statecount);
	
	

	// Load and add pngs of particular state
	for (int i = 0; i < statecount; ++i)
	{
		char buffer[128];
		fscanf_s(pFile, "%s", buffer, 128);
		mSprite.Add(buffer);
	}

	mJab.Load("Josh_Hea.wav");
}

//----------------------------------------------------------------------------------------------------

void CharacterJabRight::Unload()
{
	mSprite.Unload();
	mJab.Unload();
}

//----------------------------------------------------------------------------------------------------

void CharacterJabRight::Update(float deltaTime)
{
	// Update sprite
	mSprite.Update(deltaTime);


	if (mSprite.IsFinished())
	{
		mpOwner->ChangeState(AS_Idle);
	}
}

//----------------------------------------------------------------------------------------------------

void CharacterJabRight::Render(const SVector2& offset)
{
	const int kTextureWidth = mSprite.GetWidth();
	const int kTextureHeight = mSprite.GetHeight();
	const SVector2 ownerPos(mpOwner->GetPosition());
	const SVector2 renderPos(ownerPos.x - (kTextureWidth * 0.5f), ownerPos.y - kTextureHeight);
	bool facingLeft = mpOwner->IsFacingLeft();
	mSprite.SetPosition(renderPos + offset);
	mSprite.SetFlipH(facingLeft);
	mSprite.Render();
}

//----------------------------------------------------------------------------------------------------

void CharacterJabRight::Enter()
{
	mSprite.Play(4.0f, false);
	if (!mIsPlaying)
	{
		mJab.Play();
		mIsPlaying = true;
	}
}

//----------------------------------------------------------------------------------------------------

void CharacterJabRight::Exit()
{
	mSprite.Stop();
	mSprite.Reset();
	mIsPlaying=0;
}

//----------------------------------------------------------------------------------------------------
SRect CharacterJabRight::GetBoundingBox() const
{
	const SVector2 pos(mpOwner->GetPosition());
	if (mpOwner->IsFacingLeft())
	{
	return SRect
		(
			pos.x + 270.0f,
			pos.y + 0.0f,
			pos.x + 310.0f,
			pos.y + 300.0f
		);
	}
	else
	{
		return SRect
		(
			pos.x + 150.0f,
			pos.y + 0.0f,
			pos.x + 190.0f,
			pos.y + 300.0f
		);
	}
}
//----------------------------------------------------------------------------------------------------
SRect CharacterJabRight::GetDamageBox() const
{
	const SVector2 pos(mpOwner->GetPosition());
	if (mpOwner->IsFacingLeft())
	{
	return SRect
		(
			pos.x + 150.0f,
			pos.y + 0.0f,
			pos.x + 190.0f,
			pos.y + 300.0f
		);
	}
	else
	{
		return SRect
		(
			pos.x + 270.0f,
			pos.y + 0.0f,
			pos.x + 310.0f,
			pos.y + 300.0f
		);
	}
}